package JAVA300.第九章容器;

/**
 * 自写linkedList
 */

public class TestLinkedList {

    private Node first;
    private Node last;

    public void add(Object element){
        Node node = new Node(element);

        if (first==null){
            first = node;
            last = node;
        }else {
            node.previous = last;
            node.next = null;

            last.next = node;
            //node = last;
            last = node;
        }

    }


    @Override
    public String toString() {
        //【a,b,c】 first=a,last=c


        StringBuilder sb = new StringBuilder("[");
        Node temp = first;
      //  System.out.print("[");

        while (temp!=null){
            //System.out.print(temp.element+",");
            sb.append(temp.element+",");
            temp = temp.next;

        }
        //System.out.print("]");
        sb.setCharAt(sb.length()-1,']');
        return sb.toString();


    }



    public static void main(String[] args) {
        TestLinkedList linkedList = new TestLinkedList();
        linkedList.add("a");
        linkedList.add("b");
        linkedList.add("c");

        System.out.println(linkedList);


    }


}
